package Test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author dayu
 * @version 创建时间：2018年1月19日 上午10:13:54
 * 测试io读取文件的几种方式
 */
public class ReadFile {
    public static void main(String[] args) {
        //文件位置
        String filepath = "/Users/leiwenkang/Downloads/project/personal/offer-study/src/main/resources/桌签模板.docx";

        /** 以行为单位读取文件，常用于读面向行的格式化文件 */
        BufferedReaderReadFile(filepath);
        System.out.println("=====================");

    }


    private static void BufferedReaderReadFile(String filepath) {
        try {
            StringBuffer sb = new StringBuffer();
            BufferedReader br = new BufferedReader(new FileReader(new File(filepath)));
            String readLine = "";
            while ((readLine = br.readLine()) != null) {
                sb.append(readLine + "\n");
            }
            br.close();
            System.out.print(sb.toString());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}